//
//  warningViewController.m
//  
//
//  Created by turing on 15/11/24.
//
//

#import "warningViewController.h"
#import "warningDetailViewController.h"
#import "warningSetViewController.h"

@interface warningViewController ()
@property(nonatomic, strong)NSArray *array;


@end

@implementation warningViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSArray arrayWithObjects:@"碰撞报警", @"超速报警", @"疲劳报警", @"怠速报警", @"亏电报警", @"区域报警", nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navtitle.text = @"        告警";
    self.leftButton.hidden = YES;
    [self initWithView];

}

- (void)buttonAction:(UIButton *)button{
    warningDetailViewController *detailVC = [[warningDetailViewController alloc] initWithTitle:[self.array objectAtIndex:button.tag]];
    [self.navigationController pushViewController:detailVC animated:YES];
}

#pragma mark 初始化视图 创建button
- (void)initWithView{
    int columnOne = 0;
    int columnTwo = 0;
    for (int i = 0; i < 6; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setImage:[UIImage imageNamed:@"hy_pre"] forState:UIControlStateNormal];
        button.tag = i;
        if (i % 2 == 0) {
            columnOne ++;
            button.frame = CGRectMake((kUIScreenWidth - 50 * 2) / 3, 100 * columnOne, 50, 50);
        } else{
            columnTwo ++;
            button.frame = CGRectMake((kUIScreenWidth - 50 * 2) / 3 * 2 + 50 * 1, 100 * columnTwo, 50, 50);
        }
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];
        [self.view addSubview:button];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.origin.x - 10, button.frame.origin.y + button.frame.size.height, button.frame.size.width + 20, 20)];
        label.text = [self.array objectAtIndex:i];
        [self.view addSubview:label];
    }
    
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStylePlain target:self action:@selector(perFormAdd:)];//为导航栏添加右侧按钮

    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd  target:self action:@selector(selectRightAction:)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    /*
    
    // 导航右按钮
    self.rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightButton.frame = CGRectMake(self.view.frame.size.width - 39, 30, 30, 30);
    [self.rightButton addTarget:self action:@selector(btnDelete:) forControlEvents:UIControlEventTouchDown];
    [self.rightButton setImage:[UIImage imageNamed:@"sy_pre"] forState:UIControlStateNormal];
//    [self.rightButton setTintColor:[UIColor whiteColor]];
    [self.navigationItem setRightBarButtonItem:self.rightButton];
//    [self.view addSubview:self.rightButton];
//    [self.view bringSubviewToFront:self.rightButton];

     */
}

// 推出设置页
-(void)perFormAdd:(UIButton *)button{
    NSLog(@"设置");
}
// 推出设置页
-(void)selectRightAction:(UIButton *)button{
    NSLog(@"设置");
    warningSetViewController *warningSetVC = [[warningSetViewController alloc] init];
    [self.navigationController pushViewController:warningSetVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
